package com.tubang.logistics.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tubang.common.constant.Constants;
import com.tubang.common.util.BeanMapper;
import com.tubang.common.util.CollectionUtils;
import com.tubang.common.util.IdGenerator;
import com.tubang.common.util.StringUtils;
import com.tubang.component.entity.UserEntity;
import com.tubang.component.service.IUserService;
import com.tubang.logistics.entity.*;
import com.tubang.logistics.mapper.LogisticsOrderMapper;
import com.tubang.logistics.service.*;
import com.tubang.logistics.vo.ChangeStatusVo;
import com.tubang.logistics.vo.OrderBiddingVo;
import com.tubang.logistics.vo.OrderDispatchVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 物流公司运单 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2017-12-31
 */
@Service
public class LogisticsOrderServiceImpl extends ServiceImpl<LogisticsOrderMapper, LogisticsOrderEntity> implements ILogisticsOrderService {
    @Resource
    private IGoodsService goodsService;
    @Resource
    private IPlatformOrderService platformOrderService;
    @Resource
    private ILogisticsOrderService logisticsOrderServices;
    @Resource
    private ILogisticsOrderGoodsService logisticsOrderGoodsService;
    @Resource
    private IPlatformOrderGoodsService platformOrderGoodsService;
    @Resource
    private IShipperOrderService shipperOrderService;

    @Resource
    private IUserService userService;


    @Override
    public void creatLogisticsOrder(OrderDispatchVo orderDispatchVo) {
        List<String> goodsIds = orderDispatchVo.getGoodsIds();
        //指派到  0 公司  1 司机
        LogisticsOrderEntity logisticsOrderEntity = new LogisticsOrderEntity();
        logisticsOrderEntity.setNum(IdGenerator.INSTANCE.nextId());
        logisticsOrderEntity.setCarriageDeal(orderDispatchVo.getCarriage());
        logisticsOrderEntity.setCarriage(orderDispatchVo.getCarriage());
        logisticsOrderEntity.setCarrierMobile(orderDispatchVo.getCarrierMobile());
        logisticsOrderEntity.setCarrierName(orderDispatchVo.getCarrierName());
        logisticsOrderEntity.setCarrierId(orderDispatchVo.getCarrierId());
        logisticsOrderEntity.setContainerType(orderDispatchVo.getCarrierType());
        //设置运单状态为指派中
        logisticsOrderEntity.setStatusCode(String.valueOf(orderDispatchVo.getStatus()));
        logisticsOrderEntity.setStatusCodeDesc(orderDispatchVo.getStatusCodeDesc());
        logisticsOrderEntity.setUserId(orderDispatchVo.getUserId());
        logisticsOrderEntity.setUserType(orderDispatchVo.getUserType());
        logisticsOrderEntity.setGoodsName(orderDispatchVo.getGoodsName());
        logisticsOrderEntity.setOrderStatusCode(String.valueOf(orderDispatchVo.getStatus()));
        logisticsOrderEntity.setOrderStatusCodeDesc(orderDispatchVo.getStatusCodeDesc());
        UserEntity userEntity = userService.selectCompanyUserByUserId(orderDispatchVo.getUserId());
        if (userEntity != null) {
            logisticsOrderEntity.setUserName(userEntity.getName());
            logisticsOrderEntity.setUserMobile(userEntity.getMobile());
        }
        logisticsOrderServices.insertOrUpdate(logisticsOrderEntity);

        BigDecimal goodsWeight = new BigDecimal(0);
        LogisticsOrderGoodsEntity logisticsOrderGoodsEntity = null;
        for (String goodsId : goodsIds) {
            //保存关系表
            GoodsEntity goodsEntity = goodsService.selectById(goodsId);
            if (goodsEntity != null && Constants.DEFAULT_VAULE_ZERO.equals(goodsEntity.getParentId())) {
                goodsWeight = goodsWeight.add(goodsEntity.getWeight());
            }
            logisticsOrderGoodsEntity = logisticsOrderGoodsService.selectOrderByGoodsId(goodsId, null);
            LogisticsOrderGoodsEntity pfog = new LogisticsOrderGoodsEntity();
            pfog.setGoodsId(goodsId);
            pfog.setLogisticsOrderId(logisticsOrderEntity.getId());
            pfog.setStatusCode(Constants.DEFAULT_VAULE_ONE);
            pfog.setStatusCodeDesc("未调度");
            logisticsOrderGoodsService.insertOrUpdate(pfog);
            goodsService.updateGoodssStatus(goodsId, Constants.GOODS_STATUS_DESIGNATE);
        }

        //循环判断平台运单中的货品是否都指派完毕
        List<String> orderIds = orderDispatchVo.getOrderIds();
        if (orderIds != null && !orderIds.isEmpty()) {
            for (String id : orderIds) {
                LogisticsOrderEntity entity = new LogisticsOrderEntity();
                entity.setId(id);
                entity.setStatusCode(Constants.ORDER_WAITING_PICK_UP_GOODS);
                entity.setStatusCodeDesc("待提货");
                logisticsOrderServices.updateById(entity);
            }
        }

        if (logisticsOrderGoodsEntity != null) {
            String logisticsOrderId = logisticsOrderGoodsEntity.getLogisticsOrderId();
            LogisticsOrderEntity logisticsOrderEntitydb = logisticsOrderServices.selectById(logisticsOrderId);
            logisticsOrderEntity.setAddrFrom(logisticsOrderEntitydb.getAddrFrom());
            logisticsOrderEntity.setAddrTo(logisticsOrderEntitydb.getAddrTo());

            logisticsOrderEntity.setGoodsWeight(goodsWeight.doubleValue());
            Double carriage = orderDispatchVo.getCarriage();
            if (carriage == null) {
                carriage = logisticsOrderEntitydb.getCarriage();
            }
            logisticsOrderEntity.setAmountDeal(goodsWeight.multiply(new BigDecimal(carriage)).doubleValue());
            logisticsOrderEntity.setAmount(goodsWeight.multiply(new BigDecimal(carriage)).doubleValue());
            logisticsOrderServices.insertOrUpdate(logisticsOrderEntity);
        }
    }

    @Override
    public void creatLogisticsOrder(OrderBiddingVo platformOrderBiddingVo) {
        Date now = new Date();
        //查询订单的货品
        List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntities = logisticsOrderGoodsService.selectOrderByOrderId(platformOrderBiddingVo.getOrderId(), null);
        // List<String> goodsIds = platformOrderBiddingVo.getGoodsIds();
        LogisticsOrderEntity logisticsOrderEntity = new LogisticsOrderEntity();
        logisticsOrderEntity.setId(null);
        insertOrUpdate(logisticsOrderEntity);
        String orderId = logisticsOrderEntity.getId();
        for (LogisticsOrderGoodsEntity logisticsOrderGoodsEntity : logisticsOrderGoodsEntities) {
            //查询原单数据
            String goodsId = logisticsOrderGoodsEntity.getGoodsId();
            GoodsEntity goodsEntity = goodsService.selectById(goodsId);
            if (goodsEntity == null) continue;
            //跟新货品状态 指派中
            goodsEntity.setGoodsStatus(Constants.DEFAULT_VAULE_ZERO);
            goodsService.insertOrUpdate(goodsEntity);
            LogisticsOrderEntity logisticsOrder = logisticsOrderServices.selectById(goodsEntity.getShipperOrderId());
            //判断此商品所在订单是否有未调度的商品
            List<GoodsEntity> goodsEntities = goodsService.selectGoodssByOrderId(logisticsOrder.getId(), Constants.DEFAULT_VAULE_FU_ONE);
            if (CollectionUtils.isEmpty(goodsEntities)) {
                logisticsOrder.setStatusCode(String.valueOf(Constants.ORDER_STATUS_CODE_TAKE_GOODS));
                logisticsOrder.setStatusCodeDesc("待提货");
                logisticsOrderServices.insertOrUpdate(logisticsOrder);
            }
            BeanMapper.copy(logisticsOrder, logisticsOrderEntity);
            //保存到新订单当中
            //保存关系表
            LogisticsOrderGoodsEntity tko = new LogisticsOrderGoodsEntity();
            tko.setLogisticsOrderId(orderId);
            tko.setGoodsId(goodsId);
            tko.setCreateTime(now);
            tko.setUpdateTime(now);
            tko.setEnable(true);
            tko.setStatusCode(Constants.DEFAULT_VAULE_ONE);
            tko.setStatusCodeDesc("未调度");
            logisticsOrderGoodsService.insertOrUpdate(tko);
        }
        logisticsOrderEntity.setId(orderId);
        logisticsOrderEntity.setStatusCode(String.valueOf(platformOrderBiddingVo.getStatus()));
        logisticsOrderEntity.setStatusCodeDesc(platformOrderBiddingVo.getStatusCodeDesc());
        Double carriage = platformOrderBiddingVo.getCarriage();
        if (carriage != null) {
            logisticsOrderEntity.setCarriageDeal(carriage);
        }
        logisticsOrderEntity.setCarrierMobile(platformOrderBiddingVo.getCarrierMobile());
        logisticsOrderEntity.setCarrierName(platformOrderBiddingVo.getCarrierName());
        logisticsOrderEntity.setCarrierId(platformOrderBiddingVo.getCarrierId());
        logisticsOrderEntity.setUpdateTime(now);
        logisticsOrderEntity.setEnable(true);
        logisticsOrderEntity.setNum(IdGenerator.INSTANCE.nextId());
        logisticsOrderEntity.setCreateTime(now);
        logisticsOrderEntity.setUserId(platformOrderBiddingVo.getUserId());
        logisticsOrderEntity.setUserType(Constants.USER_TYPE_OUTSIDE_PLATFORM);
        logisticsOrderEntity.setCarriage(platformOrderBiddingVo.getCarriage());
        logisticsOrderEntity.setCarriageDeal(platformOrderBiddingVo.getCarriage());
        logisticsOrderEntity.setAmount(platformOrderBiddingVo.getAmount());
        logisticsOrderEntity.setAmountDeal(platformOrderBiddingVo.getAmount());
        logisticsOrderEntity.setGoodsName(platformOrderBiddingVo.getGoodsName());
        logisticsOrderEntity.setGoodsWeight(platformOrderBiddingVo.getGoodsWeight());
        UserEntity userEntity = userService.selectCompanyUserByUserId(platformOrderBiddingVo.getUserId());
        if (userEntity != null) {
            logisticsOrderEntity.setUserName(userEntity.getName());
            logisticsOrderEntity.setUserMobile(userEntity.getMobile());
        }

        insertOrUpdate(logisticsOrderEntity);
    }

    @Override
    public void updatelogisticsOrderStatus(List<String> orderIds, String status, String statusCodeDesc) {
        for (String orderId : orderIds) {
            LogisticsOrderEntity logisticsOrderEntity = selectById(orderId);
            if (logisticsOrderEntity == null)
                logisticsOrderEntity.setStatusCode(String.valueOf(status));
            logisticsOrderEntity.setStatusCodeDesc(statusCodeDesc);
            insertOrUpdate(logisticsOrderEntity);
        }
    }

    @Override
    public void creatLogisticsConfirmOrder(OrderBiddingVo platformOrderBiddingVo) {
        Date now = new Date();
        //查询订单的货品
        List<PlatformOrderGoodsEntity> platformOrderGoodsEntities = platformOrderGoodsService.selectOrderByOrderId(platformOrderBiddingVo.getOrderId());
        // List<String> goodsIds = platformOrderBiddingVo.getGoodsIds();
        LogisticsOrderEntity logisticsOrderEntity = new LogisticsOrderEntity();
        logisticsOrderEntity.setId(null);
        insertOrUpdate(logisticsOrderEntity);
        String orderId = logisticsOrderEntity.getId();
        for (PlatformOrderGoodsEntity platformOrderGoodsEntity : platformOrderGoodsEntities) {
            //查询原单数据
            String goodsId = platformOrderGoodsEntity.getGoodsId();
            GoodsEntity goodsEntity = goodsService.selectById(goodsId);
            if (goodsEntity == null) continue;
            //跟新货品状态 指派中
            goodsEntity.setGoodsStatus(Constants.DEFAULT_VAULE_ZERO);
            goodsService.insertOrUpdate(goodsEntity);
            ShipperOrderEntity shipperOrderEntity = shipperOrderService.selectById(goodsEntity.getShipperOrderId());
            //判断此商品所在订单是否有未调度的商品
            List<GoodsEntity> goodsEntities = goodsService.selectGoodssByOrderId(shipperOrderEntity.getId(), Constants.DEFAULT_VAULE_FU_ONE);
            if (CollectionUtils.isEmpty(goodsEntities)) {
                shipperOrderEntity.setStatusCode(String.valueOf(Constants.ORDER_STATUS_CODE_TAKE_GOODS));
                shipperOrderEntity.setStatusCodeDesc("待提货");
                shipperOrderService.insertOrUpdate(shipperOrderEntity);
            }
            BeanMapper.copy(shipperOrderEntity, logisticsOrderEntity);
            //保存到新订单当中
            //保存关系表
            LogisticsOrderGoodsEntity tko = new LogisticsOrderGoodsEntity();
            tko.setLogisticsOrderId(orderId);
            tko.setGoodsId(goodsId);
            tko.setCreateTime(now);
            tko.setUpdateTime(now);
            tko.setEnable(true);
            logisticsOrderGoodsService.insertOrUpdate(tko);
        }
        logisticsOrderEntity.setId(orderId);
        logisticsOrderEntity.setStatusCode(String.valueOf(platformOrderBiddingVo.getStatus()));
        logisticsOrderEntity.setStatusCodeDesc(platformOrderBiddingVo.getStatusCodeDesc());
        Double carriage = platformOrderBiddingVo.getCarriage();
        if (carriage != null) {
            logisticsOrderEntity.setCarriageDeal(carriage);
        }
        logisticsOrderEntity.setUpdateTime(now);
        logisticsOrderEntity.setEnable(true);
        logisticsOrderEntity.setNum(IdGenerator.INSTANCE.nextId());
        logisticsOrderEntity.setCreateTime(now);
        logisticsOrderEntity.setUserId(platformOrderBiddingVo.getCarrierId());
        logisticsOrderEntity.setUserType(Constants.USER_TYPE_OUTSIDE_PLATFORM);
        insertOrUpdate(logisticsOrderEntity);
    }

    @Override
    public void updateplatformOrderStatus(ChangeStatusVo changeStatusVo) {
        LogisticsOrderEntity order = selectById(changeStatusVo.getOrderId());
        if (order == null) return;
        order.setStatusCode(changeStatusVo.getThisStatus());
        order.setStatusCodeDesc(changeStatusVo.getThisStatusDesc());
        Double carriage = changeStatusVo.getCarriage();
        if (carriage != null) {
            order.setCarriage(carriage);
        }
        String remarks = changeStatusVo.getRemarks();
        if (StringUtils.isNotEmpty(remarks)) {
            order.setRemarks(remarks);
        }
        String cid = changeStatusVo.getCid();
        if (StringUtils.isNotEmpty(cid)) {
            order.setCarrierName(changeStatusVo.getCname());
            order.setCarrierId(cid);
            order.setCarrierMobile(changeStatusVo.getCmobile());
        }

        insertOrUpdate(order);
    }

    @Override
    public void creatLogisticsOrderLTOL(OrderBiddingVo platformOrderBiddingVo) {
        Date now = new Date();
        //查询订单的货品
        List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntities = logisticsOrderGoodsService.selectOrderByOrderId(platformOrderBiddingVo.getOrderId(), null);
        // List<String> goodsIds = platformOrderBiddingVo.getGoodsIds();
        LogisticsOrderEntity logisticsOrderEntity = new LogisticsOrderEntity();
        logisticsOrderEntity.setId(null);
        insertOrUpdate(logisticsOrderEntity);
        String orderId = logisticsOrderEntity.getId();
        for (LogisticsOrderGoodsEntity logisticsOrderGoodsEntity : logisticsOrderGoodsEntities) {
            //查询原单数据
            String goodsId = logisticsOrderGoodsEntity.getGoodsId();
            GoodsEntity goodsEntity = goodsService.selectById(goodsId);
            if (goodsEntity == null) continue;
            //跟新货品状态 指派中
            goodsEntity.setGoodsStatus(Constants.DEFAULT_VAULE_ZERO);
            goodsService.insertOrUpdate(goodsEntity);
            ShipperOrderEntity shipperOrderEntity = shipperOrderService.selectById(goodsEntity.getShipperOrderId());
            //判断此商品所在订单是否有未调度的商品
            List<GoodsEntity> goodsEntities = goodsService.selectGoodssByOrderId(shipperOrderEntity.getId(), Constants.DEFAULT_VAULE_FU_ONE);
            if (CollectionUtils.isEmpty(goodsEntities)) {
                shipperOrderEntity.setStatusCode(String.valueOf(Constants.ORDER_STATUS_CODE_TAKE_GOODS));
                shipperOrderEntity.setStatusCodeDesc("待提货");
                shipperOrderService.insertOrUpdate(shipperOrderEntity);
            }
            BeanMapper.copy(shipperOrderEntity, logisticsOrderEntity);
            //保存到新订单当中
            //保存关系表
            LogisticsOrderGoodsEntity tko = new LogisticsOrderGoodsEntity();
            tko.setLogisticsOrderId(orderId);
            tko.setGoodsId(goodsId);
            tko.setCreateTime(now);
            tko.setUpdateTime(now);
            tko.setEnable(true);
            logisticsOrderGoodsService.insertOrUpdate(tko);
        }
        logisticsOrderEntity.setId(orderId);
        logisticsOrderEntity.setStatusCode(String.valueOf(platformOrderBiddingVo.getStatus()));
        logisticsOrderEntity.setStatusCodeDesc(platformOrderBiddingVo.getStatusCodeDesc());
        Double carriage = platformOrderBiddingVo.getCarriage();
        if (carriage != null) {
            logisticsOrderEntity.setCarriageDeal(carriage);
        }
        logisticsOrderEntity.setCarrierMobile(platformOrderBiddingVo.getCarrierMobile());
        logisticsOrderEntity.setCarrierName(platformOrderBiddingVo.getCarrierName());
        logisticsOrderEntity.setCarrierId(platformOrderBiddingVo.getCarrierId());
        logisticsOrderEntity.setUpdateTime(now);
        logisticsOrderEntity.setEnable(true);
        logisticsOrderEntity.setNum(IdGenerator.INSTANCE.nextId());
        logisticsOrderEntity.setCreateTime(now);
        logisticsOrderEntity.setUserId(platformOrderBiddingVo.getUserId());
        logisticsOrderEntity.setUserType(Constants.USER_TYPE_OUTSIDE_PLATFORM);
        insertOrUpdate(logisticsOrderEntity);
    }

    @Override
    public void updateSupplyOrderStatus(ChangeStatusVo changeStatusVo) {

        LogisticsOrderEntity order = selectById(changeStatusVo.getOrderId());
        if (order == null) return;
        order.setStatusCode(changeStatusVo.getThisStatus());
        order.setStatusCodeDesc(changeStatusVo.getThisStatusDesc());
        Double carriage = changeStatusVo.getCarriage();
        if (carriage != null) {
            order.setCarriageDeal(carriage);
            Double carriageNow = order.getCarriage();
            Double amountNow = order.getAmount();
            double amountDeal = (amountNow / carriageNow) * carriage;
            order.setAmountDeal(Double.valueOf(new DecimalFormat("#.00").format(amountDeal)));
        }
        String remarks = changeStatusVo.getRemarks();
        if (StringUtils.isNotEmpty(remarks)) {
            order.setRemarks(remarks);
        }
        order.setCarrierName(changeStatusVo.getCid());
        order.setCarrierMobile(changeStatusVo.getCmobile());
        order.setCarrierId(changeStatusVo.getCid());
        insertOrUpdate(order);
    }

    @Override
    public void updateLogisticsOrderStatusTspByGoodsIds(List<String> goodsIdlist, String statusCode, String statusCodeDesc) {
        //修改货品状态
        for (String goodsId : goodsIdlist) {
            GoodsEntity goodsEntity = goodsService.selectById(goodsId);
            if (goodsEntity == null) continue;
            goodsEntity.setGoodsStatus(statusCode);
            goodsService.insertOrUpdate(goodsEntity);
            List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntities = logisticsOrderGoodsService.selectOrdersByGoodsId(goodsEntity.getShipperOrderId());
            //运输中
            for (LogisticsOrderGoodsEntity logisticsOrderGoodsEntity : logisticsOrderGoodsEntities) {
                logisticsOrderGoodsEntity.setStatusCode(statusCode);
                logisticsOrderGoodsEntity.setStatusCodeDesc(statusCodeDesc);
                logisticsOrderGoodsService.updateById(logisticsOrderGoodsEntity);
                LogisticsOrderEntity logisticsOrderEntity = logisticsOrderServices.selectById(logisticsOrderGoodsEntity.getLogisticsOrderId());
                logisticsOrderEntity.setStatusCode(statusCode);
                logisticsOrderEntity.setStatusCodeDesc(statusCodeDesc);
                logisticsOrderServices.insertOrUpdate(logisticsOrderEntity);
            }

        }


    }

    @Override
    public void updateLogisticsOrderStatusAdmByGoodsIds(List<String> goodsIdlist, String statusCode, String statusCodeDesc) {
        //修改货品状态
        for (String goodsId : goodsIdlist) {
            GoodsEntity goodsEntity = goodsService.selectById(goodsId);
            if (goodsEntity == null) continue;
            goodsEntity.setGoodsStatus(statusCode);
            goodsService.insertOrUpdate(goodsEntity);
            List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntities = logisticsOrderGoodsService.selectOrdersByGoodsId(goodsEntity.getShipperOrderId());

            if (statusCode != null && statusCode.equals(Constants.ORDER_IN_EXCEPTION)) {
                //异常 全部标记异常
                for (LogisticsOrderGoodsEntity logisticsOrderGoodsEntity : logisticsOrderGoodsEntities) {
                    logisticsOrderGoodsEntity.setStatusCode(statusCode);
                    logisticsOrderGoodsEntity.setStatusCodeDesc(statusCodeDesc);
                    logisticsOrderGoodsService.updateById(logisticsOrderGoodsEntity);
                }
            }

            if (statusCode != null && statusCode.equals(Constants.ORDER_HAVA_COMPLETED)) {
                //审核通过  判断是否所有商品都审核通过

                for (LogisticsOrderGoodsEntity logisticsOrderGoodsEntity : logisticsOrderGoodsEntities) {
                    //当前关系表状态
                    logisticsOrderGoodsEntity.setStatusCode(statusCode);
                    logisticsOrderGoodsEntity.setStatusCodeDesc(statusCodeDesc);
                    logisticsOrderGoodsService.updateById(logisticsOrderGoodsEntity);
                    String logisticsOrderId = logisticsOrderGoodsEntity.getLogisticsOrderId();
                    //查询order中其他货品状态
                    List<LogisticsOrderGoodsEntity> logorders = logisticsOrderGoodsService.selectOrderByOrderId(logisticsOrderId, null);
                    for (LogisticsOrderGoodsEntity logorder : logorders) {
                        //当前货品状态必须为已完成
                        GoodsEntity goods = goodsService.selectById(logorder.getGoodsId());
                        if (!goods.getGoodsStatus().equals(Constants.ORDER_HAVA_COMPLETED)) continue;
                        //查询这个货品所关联的所有订单
                        List<LogisticsOrderGoodsEntity> logordersRela = logisticsOrderGoodsService.selectOrdersByGoodsId(goods.getId());
                        for (LogisticsOrderGoodsEntity orderGoodsEntity : logordersRela) {
                            GoodsEntity goodsRela = goodsService.selectById(orderGoodsEntity.getGoodsId());
                            if (!goodsRela.getGoodsStatus().equals(Constants.ORDER_HAVA_COMPLETED)) return;
                            LogisticsOrderEntity logisticsOrderEntityRela = logisticsOrderServices.selectById(orderGoodsEntity.getLogisticsOrderId());
                            logisticsOrderEntityRela.setStatusCode(statusCode);
                            logisticsOrderEntityRela.setStatusCodeDesc(statusCodeDesc);
                            logisticsOrderServices.insertOrUpdate(logisticsOrderEntityRela);

                        }
                    }
                }

            }

        }

    }

    @Override
    public void orderRobackStatuscode(LogisticsOrderEntity logisticsOrderEntity) {
        //数据回滚
        logisticsOrderEntity.setEnable(false);
        List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntities = logisticsOrderGoodsService.selectOrderByOrderId(logisticsOrderEntity.getId(), null);

        for (LogisticsOrderGoodsEntity logisticsOrderGoodsEntity : logisticsOrderGoodsEntities) {
            //查询与当前所有货品相关信息的订单关系表数据
            List<LogisticsOrderGoodsEntity> logisticsOrderGoodss = logisticsOrderGoodsService.selectOrdersByGoodsId(logisticsOrderGoodsEntity.getGoodsId());
            for (LogisticsOrderGoodsEntity orderGoodss : logisticsOrderGoodss) {
                LogisticsOrderEntity logisticsOrder = logisticsOrderServices.selectById(orderGoodss.getLogisticsOrderId());
                if (logisticsOrder == null) continue;
                if (!StringUtils.equals(logisticsOrderEntity.getUserId(), logisticsOrder.getCarrierId()))
                    continue;
                //修改订单已经订单关联表的货品状态
                logisticsOrder.setStatusCode(String.valueOf(Constants.ORDER_STATUS_CODE_RELEASE_GOODS));
                logisticsOrder.setStatusCodeDesc("待调度");
                logisticsOrderServices.insertOrUpdate(logisticsOrder);
                orderGoodss.setStatusCode(Constants.DEFAULT_VAULE_ONE);
                orderGoodss.setStatusCodeDesc("未调度");
                logisticsOrderGoodsService.insertOrUpdate(orderGoodss);
            }
        }
    }
}

